package com.hibase.core.excel.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.hibase.core.excel.entity.MdsExcelImportLog;
import com.hibase.core.excel.mapper.MdsExcelImportLogMapper;
import com.hibase.core.excel.service.MdsExcelImportLogService;
import com.hibase.core.excel.vo.bizlog.MdsExcelImportLogSearchVO;
import com.hibase.core.mybatis.service.BaseServiceImpl;
import org.springframework.stereotype.Service;

/**
 * Excel 导入日志服务
 *
 * @author <a href="mailto:xiongliyi@hichain.com">Ian Xiong</a>
 * @since 1.5.01-V2
 */
@Service
public class MdsExcelImportLogServiceImpl extends BaseServiceImpl<MdsExcelImportLogMapper, MdsExcelImportLog> implements MdsExcelImportLogService {

    /**
     * 分页查询
     *
     * @param searchVO 查询条件
     * @return 返回导入日志数据集
     */
    @Override
    public PageInfo queryPage(MdsExcelImportLogSearchVO searchVO) {
        QueryWrapper<MdsExcelImportLog> queryWrapper = new QueryWrapper<>();

        if (StrUtil.isNotEmpty(searchVO.getKeyWord())) {
            queryWrapper.lambda().like(MdsExcelImportLog::getName, searchVO.getKeyWord());
        }

        // 业务数据集ID
        if (StrUtil.isNotEmpty(searchVO.getBizDataId())) {
            queryWrapper.lambda().eq(MdsExcelImportLog::getBizDataId, searchVO.getBizDataId());
        }

        if (StrUtil.isNotEmpty(searchVO.getName())) {
            queryWrapper.lambda().like(MdsExcelImportLog::getName, searchVO.getName());
        }


        if (searchVO.getErrRowIndex() != null) {
            queryWrapper.lambda().eq(MdsExcelImportLog::getErrRowIndex, searchVO.getErrRowIndex());
        }

        if (searchVO.getErrColumnIndex() != null) {
            queryWrapper.lambda().eq(MdsExcelImportLog::getErrColumnIndex, searchVO.getErrColumnIndex());
        }

        if (searchVO.getCellData() != null) {
            queryWrapper.lambda().like(MdsExcelImportLog::getCellData, searchVO.getCellData());
        }
        if (searchVO.getExcelContentProperty() != null) {
            queryWrapper.lambda().like(MdsExcelImportLog::getExcelContentProperty, searchVO.getExcelContentProperty());
        }


        queryWrapper.lambda().orderByDesc(MdsExcelImportLog::getCreateTime);


        return super.page(searchVO, queryWrapper);
    }
}
